define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wx/wximportlog/index',
                    add_url: 'wx/wxorder/add',
                    edit_url: 'wx/wximportlog/edit',
                    del_url: 'wx/wximportlog/del',
                    multi_url: 'wx/wximportlog/multi',
                    table: 'wximportlog',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true,formatter:function (value,row,index) {
                            if(row.dc == 1)
                            {
                              return {
                                disabled: true
                              };
                            }
                          }},
                        {field: 'id', title: __('Id')},
                        {field: 'info.agent_name', title: __('Info.agent_name')},
                        {field: 'order_ids', title: __('订单详情'),formatter:function (value,row,index) {
                            return '<a href="/admin/wx/wxorder/index/ids/'+row.id+'" class="addtabsit btn btn-info" data-value="订单详情-'+row.info.agent_name+'" title="订单详情-'+row.info.agent_name+'">查看详情</a>';
                          }},
                        {field: 'check', title: __('审核统计')},
                        {field: 'courierBut', title: __('状态统计')},
                        {field: 'cw', title: __('财务导出')},
                        {field: 'wl', title: __('物流导出')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
          $(document).on("click", ".btn-config", function () {
            Fast.api.open('wx/wxorder/config', '提分超市订单', $(this).data() || {});
          });
          $(document).on("click", ".btn-importcw", function () {
            var that = this;
            var ids = Table.api.selectedids(table);
            ids = ids.join(',');
            window.open("/admin/wx/wximportlog/cwexport/ids/"+ids,"_blank");
          });
          $(document).on("click", ".btn-importwl", function () {
            var that = this;
            var ids = Table.api.selectedids(table);
            ids = ids.join(',');
            window.open("/admin/wx/wximportlog/wlexport/ids/"+ids,"_blank");
          });
            // 为表格绑定事件
            Table.api.bindevent(table);
          // 启动和暂停按钮
          $(document).on("click", ".btn-start,.btn-pause", function () {
            //在table外不可以使用添加.btn-change的方法
            //只能自己调用Table.api.multi实现
            //如果操作全部则ids可以置为空
            var ids = Table.api.selectedids(table);
            Table.api.multi("manual", ids.join(","), table, this);
          });
          //导入
          require(['upload'], function (Upload) {
            //物流单号导入 下册
            //物流单号导入
            Upload.api.plupload($('.btn-importwlx'), function (data, ret) {
              Fast.api.ajax({
                url:'wx/wxorder/importwlx' ,
                data: {file: data.url},
              }, function (data, ret) {
                if(data.length >= 1){
                  var htmlstr = '';
                  data.forEach(function (element, index, array) {
                    htmlstr +='<li>'+array[index]+' </li>';
                  });
                  layer.open({
                    type: 1,
                    title: '错误的数据',
                    skin: 'layui-layer-demo', //样式类名
                    closeBtn: 1, //不显示关闭按钮
                    anim: 2,
                    shadeClose: true, //开启遮罩关闭
                    content: '<ul>'+htmlstr+'</ul>'
                  });
                }
                table.bootstrapTable('refresh');
              });
            });
          });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});